package com.briup.shopadmin.web.handler;

import com.briup.shopadmin.common.GlobalException;
import com.briup.shopadmin.common.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public Result handler(Exception e){
        if (e instanceof GlobalException){
            GlobalException ex= (GlobalException) e;
            return  Result.error(ex.getCode(),ex.getMessage());
        }else {
            e.printStackTrace();
            return  Result.error(50000,"系统内部错误");
        }

    }
}
